package com.mb.common.utils;

import org.apache.commons.codec.binary.Base64;

public class Base64Utils {

    /**
     * 编码
     * @param parms
     * @return
     */
    public static String encode(String parms){
        return Base64.encodeBase64String(parms.getBytes());
    }

    /**
     * 解码
     * @param parms
     * @return
     */
    public static String decode(String parms){
        String ret = "";
        try {
            parms = parms.replaceAll(" ", "+");
            parms = parms.replaceAll("\n", "");
            byte [] bytes =  Base64.decodeBase64(parms);
            ret = new String(bytes,"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }
	
}
